<?php


if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}

if ($_GET['mod'] == 'list') {
    return include 'source/plugin/zhibo/template/touch/list.php';
}

if ($_GET['ac'] == 'activity' && $_GET['op'] == 'zan') {
    return include 'zan.inc.php';
}

if ($_GET['ac'] == 'activity' && $_GET['op'] == 'view') {
    return include 'view.inc.php';
}

if ($_GET['ac'] == 'activity') {
    return include(template('zhibo:add'));
}

if ($_GET['ac'] == 'activity' && $_GET['op'] == 'edit') {
    return include 'edit.inc.php';
}

if ($_GET['ac'] == 'activity' && $_GET['op'] == 'edit2') {
    return include 'edit2.inc.php';
}

if ($_GET['ac'] == 'activity' && $_GET['op'] == 'del') {
    return include 'del.inc.php';
}

if($_GET['mod'] == 'ajax' && $_GET['ac'] == 'comment'){
    return include 'comment.inc.php';
}

if($_GET['mod'] == 'ajax' && $_GET['ac'] == 'add_comment'){
    return include 'add_comment.inc.php';
}



//if ($_GET['ac'] == 'gift') {
//    return include(template('zhibo:gift'));
//}
//
//
//if ($_GET['ac'] == 'mobile') {
//    return include(template('zhibo:index'));
//}

//if ($_GET['ac'] == 'mobile' && $_GET['op'] == 'view') {
//    return include 'view.inc.php';
//}


//mod=ajax&ac=comment&identify={$data}&page="+page

//读取数据库数据传递到前端
$data = C::t('#zhibo#zhibo')->getList();

foreach ($data as $k => $v) {
    $url = 'https://bikeshopapi.olbike.com/V2/?service=Live.GetListDetails';
    $postData = [
        'channelId' => $v['channelId']
    ];
    $ch = curl_init();  //开启curl
    curl_setopt($ch, CURLOPT_URL, $url);  //curl请求地址
    curl_setopt($ch, CURLOPT_POST, 1);   //请求一个正规的HTTP POST请求, 第三个参数要非零
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   //默认0是直接将信息显示在浏览器中,设为1表示就能取值
    curl_setopt($ch, CURLOPT_HEADER, 0);  //如果成功,请求头信息不显示, 1就显示
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);  //使用POST方法请求

    $buf = curl_exec($ch);    //抓取URL并把它传递给浏览器
    $newBuf[] = json_decode($buf);

    foreach($newBuf as $k2=>$v2){
        $data[$k]['channel_status'] = $v2->data[0]->channel_status;  //获取腾讯云的状态,放入数组中
    }

    $data[$k]['downstream_address'] = json_decode($data[$k]['downstream_address'],true);
}

include(template('zhibo:index'));


